package com.example.demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.demo.entity.EconomicIndicators;
import com.example.demo.entity.GeneralPublicBudgetRevenue;
import com.example.demo.entity.MinEconomicIndicators;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface EconomicIndicatorsMapper extends BaseMapper<EconomicIndicators> {

    /**
     *季度地区生产总值
     * @param year 年份（int）
     *@return List<QuarterlyGrossRegionalProduct>
     */
    @Select("select * from economic_indicators where year(statisticalTime) = #{year} - 1 and month(statisticalTime) in (9,10,11,12) and indicators = '地区生产总值'" +
            " union select * from economic_indicators where year(statisticalTime) = #{year} and indicators = '地区生产总值' order by month(statisticalTime) asc")
    List<EconomicIndicators> findQuarterlyCumulativeProduction(int year);

    /**
     * 一般公共预算收入
     * @param year 年份（int）
     *@return List<GeneralPublicBudgetRevenue>
     */
    @Select("select month(e1.statisticalTime) `month` ,e1.thisMonth,e1.monthOnMonth,e1.accumulate,e2.accumulate taxProportion " +
            "from economic_indicators e1 left join economic_indicators e2 on year(e1.statisticalTime) = year(e2.statisticalTime) " +
            "and month(e1.statisticalTime) = month(e2.statisticalTime) where e1.indicators = '一般公共预算收入' and e2.indicators = '#税收占比' " +
            "and year(e1.statisticalTime) = #{year} order by month(e1.statisticalTime) asc")
    List<GeneralPublicBudgetRevenue> findGeneralPublicBudgetRevenue(int year);

    /**
     * 年度任务及单位
     * @param year 年份（int），indicators 指标 （String）
     *@return EconomicIndicators
     */
    @Select("select * from economic_indicators where year(statisticalTime) = #{year} and indicators = #{indicators} limit 1")
    EconomicIndicators findAnnualTasks(int year,String indicators);

    /**
     * 全社会固定资产投资
     * 工业投资
     * 规上工业总产值
     * 社会消费品零售总额
     * 进出口总额
     * 出口总额
     * 实际使用外资
     * @param year 年份（int）,indicators 指标 (String)
     * @return List<MinEconomicIndicators>
     */
    @Select("select month(statisticalTime) `month`,thisMonth,monthOnMonth,accumulate from economic_indicators where indicators = #{indicators} " +
            "and year(statisticalTime) = #{year} order by month(statisticalTime) asc")
    List<MinEconomicIndicators> findEconomicIndicatorsByIndicators(int year,String indicators);
}
